   //初始化数据
   var initData = function(){
	    var param = {
	    	phase_id:phase_id,
	    	major_id:major_id,
	    	content_id:content_id
	    }
		$.ajax({
	        url: base + "/dataCenter/businessdata/findDesignCellByContentIdAndPhaseId",
	        data: param,
	        success: function (data, textStatus, jqXHR) {
	        	if(data != null){
		        	var dataObj ={
		        			"list":data,
		         			"dataTool":{
		         				"title":{
		         					 "id":"id"
		          			      	,"design_cell_table_code": "设计单元编号"
		          			      	,"design_cell_table_name": "设计单元名称"
		          			      	,"orderBy":"排序规则"
		          			      	,"create_time":"创建时间"
		          			      	,"update_time":"更新时间"
		          			      	,"operation":"操作"
		            			},
		            			"titleCheckbox":false,
								"btn":[{"event":"moveUp","name":"上移"},
								       {"event":"moveDown","name":"下移"},
								       {"event":"topr","name":"置顶"},
								       {"event":"floor","name":"置底"}]
							}
			  		};
		        	showTable('view', dataObj);
	        	}
	        },
	        error: function () {
	        }
	    });
   }
   
   var go_back = function(){
       var url = base+"/dataCenter/variableLibrary?name=设计单元库";
	   $.get(url, function(result){
		   $("#content").html("");
		   $("#content").html(result);
	   });
	   return false;
   }
   
   var move = function(id,move_type){
	   var tr_cid = $("tbody").children("tr");
	   $.each(tr_cid,function(index,value){
		   if(index > 0){
			   $.each($(this).children("td"),function(index,value){
				   var field_name = $(this).attr("field");
				   var field_value = $.trim($(this).text());
				   if(field_name == "id" && field_value == id){
					   var move_element = $(this).parent();//将要移动的元素
					   if("up" == move_type){
						   //判断要移动的元素是不是第一个元素
						   var prev_elements = $(this).parent().prevAll();
						   if(prev_elements.length > 1){
							   var prev_element = $(this).parent().prev();
							   prev_element.before(move_element);//在每个匹配的元素之前插入内容。
						   }else{
								layer.msg("第一个元素无法上移!", {icon : 5});
						   }
					   }else if("down" == move_type){
						 //判断要移动的元素是不是最后一个元素
						   var next_elements = $(this).parent().nextAll();
						   if(next_elements.length > 0){
							   var next_element = $(this).parent().next();
							   next_element.after(move_element);//在每个匹配的元素之后插入内容。
						   }else{
							   layer.msg("最后一个元素无法下移!", {icon : 5});
						   }
					   }else if("top" == move_type){
						   //元素置顶
						   //判断要移动的元素是不是第一个元素
						   var prev_elements = $(this).parent().prevAll();
						   if(prev_elements.length > 1){
							   var first_element = $(this).parent().parent().children("tr").first().next();
							   first_element.before(move_element);//置顶元素
						   }else{
								layer.msg("已置顶元素无法置顶!", {icon : 5});
						   }
						   
					   }else if("floor" == move_type){
						   var next_elements = $(this).parent().nextAll();
						   if(next_elements.length > 0){
							   var last_element = $(this).parent().parent().children("tr").last();
							   last_element.after(move_element);
						   }else{
							   layer.msg("已置底元素无法置底！", {icon : 5});
						   }
					   }
				   }
			   });
		   }
	   });
   }
   
   //保存排序结果
   var saveData = function(){
	   var data_arr = [];
	   var tr_cid = $("tbody").children("tr");
	   $.each(tr_cid,function(index,value){
		   if(index > 0){
			   var data_json = {};
			   data_json.order_num = index;
			   $.each($(this).children("td"),function(index,value){
				   var field_name = $(this).attr("field");
				   var field_value = $.trim($(this).text());
				   if(field_name == "id"){
					   data_json.design_cell_id = field_value;
				   }
			   });
			   data_arr.push(data_json);
		   }
	   });
	   
		$.ajax({
	        url: base + "/dataCenter/businessdata/updateDesignCellOrderNum",
	        data: {order_list:JSON.stringify(data_arr)},
	        async:false,
	        success: function (data, textStatus, jqXHR) {
			     if(data.statusCode == 0){
					  	layer.msg(data.message, {
							icon : 1
					  	});
				     }else{
						layer.msg(data.message, {
							icon : 5
						});
				    }
	        },
	        error: function () {
	        }
	    });
	   initData();
   }
   
   var moveUp = function(obj){
	   move(obj.id,"up");
   }
   
   var moveDown = function(obj){
	   move(obj.id,"down");
   }
   
   var floor = function(obj){
	   move(obj.id,"floor");
   }
   
   var topr = function(obj){
	   move(obj.id,"top");
   }

   $(document).ready(function(){
	   initData();
	   $("#submit_btn").click(saveData);
   });